package com.klhappy.houyuan.view;

import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.klhappy.houyuan.HouYuanApplication;
import com.klhappy.houyuan.R;
import com.klhappy.houyuan.utils.ConfigManager;

/**
 * Created by MrPu on 15/12/3.
 */
public class AbsFragment extends Fragment{
    private Dialog mDialog = null;
    private Toast toast;
    public ConfigManager mConfigManage = null;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    public void showDialog(String msg) {
        mDialog = new Dialog(getActivity(), R.style.progress_dialog);
        mDialog.setContentView(R.layout.dialog);
        mDialog.setCancelable(true);
        mDialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
        TextView tv_Msg = (TextView) mDialog.findViewById(R.id.id_tv_loadingmsg);
        tv_Msg.setText(msg);
        mDialog.show();
    }


    public HouYuanApplication getAppEnv() {
        return (HouYuanApplication)getActivity().getApplication();
    }

    public void closeDialog() {
        if(mDialog != null) {
            mDialog.dismiss();
            mDialog = null;
        }
    }

    public void showToast( String msg) {
        if (toast != null){
            toast.cancel();
        }
        toast = Toast.makeText(getActivity(), msg, Toast.LENGTH_LONG);
        toast.show();
    }

    public void showToast( int msg) {
        if (toast != null){
            toast.cancel();
        }
        toast = Toast.makeText(getActivity(), msg, Toast.LENGTH_LONG);
        toast.show();
    }

    public void showToastx(String msg){
        if (toast != null){
            toast.cancel();
        }
        toast = Toast.makeText(getActivity(), msg, Toast.LENGTH_LONG);
        //可以控制toast显示的位置
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();

    }
}
